// GJ_BPA.cpp: implementation of the CGJ_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/GJ_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGJ_BPA::CGJ_BPA()
{
	m_chType = 'G';
	m_chSubType = 'J';
	m_chChangeCode = ' ';

	m_dT1 = 0;
	m_dEpsilon = 0;
	m_dK1 = 0;
	m_chI = '1';
	m_dKp = 0;
	m_dKd = 0;
	m_dKi = 0;
	m_dINTGmax = 0;
	m_dINTGmin = 0;
	m_dPIDmax = 0;
	m_dPIDmin = 0;
	m_dK2 = 0;
	m_dWmax = 0;
	m_dWmin = 0;

	m_strCardType[0] = 'G';

}

CGJ_BPA::CGJ_BPA(CGJ_BPA &gjBPA):CUnit_BPA(gjBPA)
{
	m_dT1 = gjBPA.m_dT1;
	m_dEpsilon = gjBPA.m_dEpsilon;
	m_dK1 = gjBPA.m_dK1;
	m_chI = gjBPA.m_chI;
	m_dKp = gjBPA.m_dKp;
	m_dKd = gjBPA.m_dKd;
	m_dKi = gjBPA.m_dKi;
	m_dINTGmax = gjBPA.m_dINTGmax;
	m_dINTGmin = gjBPA.m_dINTGmin;
	m_dPIDmax = gjBPA.m_dPIDmax;
	m_dPIDmin = gjBPA.m_dPIDmin;
	m_dK2 = gjBPA.m_dK2;
	m_dWmax = gjBPA.m_dWmax;
	m_dWmin = gjBPA.m_dWmin;
}

CGJ_BPA::~CGJ_BPA()
{

}

bool CGJ_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CGJ_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;

	m_dT1 = StrToDouble(&buffer[16],5,3);
	if(EndOfSec(&buffer[16],5))
		return true;

	m_dEpsilon = StrToDouble(&buffer[21],6,4);
	if(EndOfSec(&buffer[21],6))
		return true;

	m_dK1 = StrToDouble(&buffer[27],5,2);
	if(EndOfSec(&buffer[27],5))
		return true;

	m_chI = buffer[32];
	if(EndOfSec(&buffer[32],1))
		return true;

	m_dKp = StrToDouble(&buffer[33],5,3);
	if(EndOfSec(&buffer[33],5))
		return true;

	m_dKd = StrToDouble(&buffer[38],5,3);
	if(EndOfSec(&buffer[38],5))
		return true;

	m_dKi = StrToDouble(&buffer[43],5,3);
	if(EndOfSec(&buffer[43],5))
		return true;

	m_dINTGmax = StrToDouble(&buffer[48],4,2);
	if(EndOfSec(&buffer[48],4))
		return true;

	m_dINTGmin = StrToDouble(&buffer[52],4,2);
	if(EndOfSec(&buffer[52],4))
		return true;

	m_dPIDmax = StrToDouble(&buffer[56],4,2);
	if(EndOfSec(&buffer[56],4))
		return true;

	m_dPIDmin = StrToDouble(&buffer[60],4,2);
	if(EndOfSec(&buffer[60],4))
		return true;

	m_dK2 = StrToDouble(&buffer[64],5,3);
	if(EndOfSec(&buffer[64],5))
		return true;

	m_dWmax = StrToDouble(&buffer[69],5,3);
	if(EndOfSec(&buffer[69],5))
		return true;

	m_dWmin = StrToDouble(&buffer[74],5,3);
	if(EndOfSec(&buffer[74],5))
		return true;

	return true;
}

bool CGJ_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CGJ_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dT1,&buffer[16],5,3);
	DoubleToStr(m_dEpsilon,&buffer[21],6,4);
	DoubleToStr(m_dK1,&buffer[27],5,2);
	buffer[32] = m_chI;
	DoubleToStr(m_dKp,&buffer[33],5,3);
	DoubleToStr(m_dKd,&buffer[38],5,3);
	DoubleToStr(m_dKi,&buffer[43],5,3);
	DoubleToStr(m_dINTGmax,&buffer[48],4,2);
	DoubleToStr(m_dINTGmin,&buffer[52],4,2);
	DoubleToStr(m_dPIDmax,&buffer[56],4,2);
	DoubleToStr(m_dPIDmin,&buffer[60],4,2);
	DoubleToStr(m_dK2,&buffer[64],5,3);
	DoubleToStr(m_dWmax,&buffer[69],5,3);
	DoubleToStr(m_dWmin,&buffer[74],5,3);

	return true;
}